refactor(storage): caller owns version arithmetic for optimistic locking#149
Merged
Conversation
Storage Update* methods previously did `SET version = version + 1` internally, mutating a value the caller didn't supply and making it easy for in-memory entity versions to drift from the database. Per discussion in #C09N26TQLLA, version arithmetic now lives in the controller: Update* takes both oldVersion (the where-clause guard) and newVersion (the value to write); the store performs a pure conditional write. Controllers compute newVersion = oldVersion + 1 before the call and only assign entity.Version = newVersion after a successful write, so error paths leave the in-memory version consistent with the DB. Updates: - RequestStore.UpdateState - BatchStore.UpdateState, UpdateScoreAndState - BatchDependentStore.UpdateDependents - conclude, score, batch controllers + tests - Integration storage suite - New extension/storage/README.md documenting the contract - CLAUDE.md "Optimistic locking" bullet rewritten with the contract and a correct example (the prior WithStatus example showed the anti-pattern that prompted this change)
sbalabanov
approved these changes
May 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Storage Update* methods previously did
SET version = version + 1internally, mutating a value the caller didn't supply and making it
easy for in-memory entity versions to drift from the database. Per
discussion in #C09N26TQLLA, version arithmetic now lives in the
controller: Update* takes both oldVersion (the where-clause guard)
and newVersion (the value to write); the store performs a pure
conditional write.
Controllers compute newVersion = oldVersion + 1 before the call and
only assign entity.Version = newVersion after a successful write,
so error paths leave the in-memory version consistent with the DB.
Updates:
and a correct example (the prior WithStatus example showed the
anti-pattern that prompted this change)